/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package compilador;

import an_semantico.AnSemantico;
import an_lexico.AnLexico;
import an_sintatico.AnSintatico;
import an_sintatico.AnSintaticoFactory;
import an_lexico.AnLexicoFactory;
import an_semantico.AnSemanticoFactory;

/**
 *
 * @author fernando
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        AnLexicoFactory f = AnLexicoFactory.getFactory();
        AnSintaticoFactory sintaticoFactory = new AnSintaticoFactory();
        AnSemanticoFactory semanticoFactory = new AnSemanticoFactory();

        String sourcePath = "", outputPath = "";
        /**
         * Default parameters
         */
        boolean arg_source_file = false;
        boolean arg_output_file = false;

        for (String A : args) {
            /**
             * Parameters of Options
             */
            System.out.println("arg = " + A);
            if (arg_source_file) {
                sourcePath = A;
                arg_source_file = false;
                System.out.println("Compilando: " + A);
            }
            if (arg_output_file) {
                outputPath = A;
                arg_output_file = false;
                System.out.println("Saida: " + A);
            }
            /**
             * Options
             */
            if (A.equals("-i")) {
                arg_source_file = true;
            }
            if (A.equals("-o")) {
                arg_output_file = true;
            }
        }

        AnLexico lex = f.createAnLexico(sourcePath);

        lex.printLex();
        //AnSemantico sem = f.createAnSemantico();
        AnSemantico sem = semanticoFactory.criaSemantico(outputPath);
        AnSintatico sint = sintaticoFactory.createAnSintatico(lex, sem);

        /*
         * Testes
         */
        //lex.printTT();
        //sint.printAnSintatico();
        System.out.print("\n\n\n");

        sint.analyze();
    }
}
